x = input()
m = 0
if 999 < int(x) < 10000:
    for i in range(0,4):
        for j in range(i+1,5):
            c = 0
            for g in range(1,int(x[i:j])+1):
                if int(x[i:j])%g == 0:
                    c += 1
            if c == 2:
                o = int(x[i:j])
                m = max(m,o)
print(m)





